package chapter7;

public class IdentityHashCodeTest {
    public static void main(String[] args) {
        String s1 = new String("Hello");
        String s2 = new String("Hello");
        //String类改写了hashCode，比较字符序列。所以s1和s2的hashCode值相等
        System.out.println(s1.hashCode() + "----" + s2.hashCode());
        //s1和s2是不同的对象，所以identityHashCode方法返回的两个对象的hashCode不相同
        System.out.println(System.identityHashCode(s1) + "----" + System.identityHashCode(s2));
        String s3 = "Java";
        String s4 = "Java";
        //s3和s4是一个对象，所以identityHashCode返回的hashCode码相同
        System.out.println(System.identityHashCode(s3) + "----" + System.identityHashCode(s4));
    }
}
